﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;

namespace Jy123.Web.Module.Club
{
    public class Club_Star : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string type = context.Request.QueryString["Type"];
            string cIdString = context.Request.QueryString["ClubId"];
            if (!string.IsNullOrEmpty(cIdString))
            {
                int cId = int.Parse(cIdString);
                Jy123.BLL.Club_Main BLLClub = new Jy123.BLL.Club_Main();
                Jy123.Model.Club_Main club = BLLClub.GetModel(cId);
                StringBuilder sbString = new StringBuilder();
                Jy123.BLL.Club_StarRecord BLLRecord = new Jy123.BLL.Club_StarRecord();
                Jy123.BLL.Club.CModule BLLCModule = new Jy123.BLL.Club.CModule();
                List<Jy123.Model.Club_StarRecord> listRecord = BLLCModule.GetClubStar(cId);
                int peakValue = 100;//需要改进
                int maxLength = 150;
                Jy123.BLL.Public_Star BLLStar = new Jy123.BLL.Public_Star();
                List<Jy123.Model.Public_Star> listStar = BLLStar.GetModelList(string.Empty);
                Dictionary<int, Jy123.Model.Public_Star> dicStar = new Dictionary<int, Jy123.Model.Public_Star>();
                foreach (Jy123.Model.Public_Star star in listStar)
                {
                    dicStar.Add(star.ID, star);
                }
                Jy123.BLL.Public_StarQueueName BLLQName = new Jy123.BLL.Public_StarQueueName();
                List<Jy123.Model.Public_StarQueueName> listQName = BLLQName.GetModelList(string.Empty);
                Dictionary<int, string> dicQName = new Dictionary<int, string>();
                foreach (Jy123.Model.Public_StarQueueName qName in listQName)
                {
                    dicQName.Add(qName.ID, qName.QueueName);
                }
                foreach (Jy123.Model.Club_StarRecord record in listRecord)
                {
                    Jy123.Model.Public_Star cStar = dicStar[record.FStar.Value];
                    string strStar = context.Cache["clubstar"].ToString();
                    strStar = strStar.Replace("$StarImageSrc$", cStar.Model);
                    strStar = strStar.Replace("$StarName$", cStar.SName);
                    strStar = strStar.Replace("$Skill$", cStar.Skill.Value.ToString());
                    strStar = strStar.Replace("$Physical$", cStar.PhysicalFitness.Value.ToString());
                    strStar = strStar.Replace("$Liveness$", cStar.Liveness.Value.ToString());
                    strStar = strStar.Replace("$Moral$", cStar.Moral.Value.ToString());
                    strStar = strStar.Replace("$Exp$", cStar.Experience.Value.ToString());
                    int width;
                    width = cStar.Skill.Value * maxLength / peakValue;
                    string firstString = "height:4px;width:";
                    strStar = strStar.Replace("$sstyle$", firstString + width.ToString() + ";");
                    width = cStar.PhysicalFitness.Value * maxLength / peakValue;
                    strStar = strStar.Replace("$pstyle$", firstString + width.ToString() + ";");
                    width = cStar.Liveness.Value * maxLength / peakValue;
                    strStar = strStar.Replace("$lstyle$", firstString + width.ToString() + ";");
                    width = cStar.Moral.Value * maxLength / peakValue;
                    strStar = strStar.Replace("$mstyle$", firstString + width.ToString() + ";");
                    string[] strDes = cStar.Description.Split(',');
                    string[] strValues = cStar.DValues.Split(',');
                    StringBuilder sbQName = new StringBuilder();
                    for (int i = 0; i < strDes.Length; i++)
                    {
                        string cStr = strDes[i];
                        if (!string.IsNullOrEmpty(cStr))
                        {
                            string starLi = context.Cache["clubstarli"].ToString();
                            int qId = int.Parse(cStr);
                            string cQName = dicQName[qId];
                            string cValue = strValues[i];
                            starLi = starLi.Replace("$LiContent$", cQName + " " + cValue);
                            sbQName.Append(starLi);
                        }
                    }
                    strStar = strStar.Replace("$Li$", sbQName.ToString());
                    sbString.Append(strStar);
                }
                if (sbString.Length > 0)
                {
                    context.Response.Write(sbString.ToString());
                }
                else
                {
                    context.Response.Write("你还没有任何球星，请去球星市场购买");
                }

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
